//----------------------------------------------------------------------------------------------------
// Flash Player Version Detection
//----------------------------------------------------------------------------------------------------
// v1.6    Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
// v1.6.1: Copyright 2008 Webunity, All rights reserved.
//         - Refactored the AC_Generateobj function to utilise the new AC_Generate function which is used by jQuery.uploader
//----------------------------------------------------------------------------------------------------

// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;


function AC_Generate(objAttrs, params, embedAttrs) {
    var str = '';

    if (isIE && isWin && !isOpera) {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		str += '>';

  		for (var i in params)
  			str += '<param name="' + i + '" value="' + params[i] + '" />';

  		str += '</object>';
    } else {
  		str += '<embed ';

  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';

  		str += '> </embed>';
    }

    return str;
}

function AC_AddExtension(src, ext) {
	if (src.indexOf(ext) != -1)
		return src;
	return (src.indexOf('?') != -1) ? src.replace(/\?/, ext+'?') : src + ext;
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
	var ret = new Object();
	ret.embedAttrs = new Object();
	ret.params = new Object();
	ret.objAttrs = new Object();
	for (var i=0; i < args.length; i=i+2) {
		var currArg = args[i].toLowerCase();
		switch (currArg) {
			case "classid":
				break;
			case "pluginspage":
				ret.embedAttrs[args[i]] = args[i+1];
				break;
			case "src":
			case "movie":
				args[i+1] = AC_AddExtension(args[i+1], ext);
				ret.embedAttrs["src"] = args[i+1];
				ret.params[srcParamName] = args[i+1];
				break;
			case "onafterupdate":
			case "onbeforeupdate":
			case "onblur":
			case "oncellchange":
			case "onclick":
			case "ondblClick":
			case "ondrag":
			case "ondragend":
			case "ondragenter":
			case "ondragleave":
			case "ondragover":
			case "ondrop":
			case "onfinish":
			case "onfocus":
			case "onhelp":
			case "onmousedown":
			case "onmouseup":
			case "onmouseover":
			case "onmousemove":
			case "onmouseout":
			case "onkeypress":
			case "onkeydown":
			case "onkeyup":
			case "onload":
			case "onlosecapture":
			case "onpropertychange":
			case "onreadystatechange":
			case "onrowsdelete":
			case "onrowenter":
			case "onrowexit":
			case "onrowsinserted":
			case "onstart":
			case "onscroll":
			case "onbeforeeditfocus":
			case "onactivate":
			case "onbeforedeactivate":
			case "ondeactivate":
			case "type":
			case "codebase":
				ret.objAttrs[args[i]] = args[i+1];
				break;
			case "id":
			case "width":
			case "height":
			case "align":
			case "vspace":
			case "hspace":
			case "class":
			case "title":
			case "accesskey":
			case "name":
			case "tabindex":
				ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
				break;
			default:
				ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
		}
	}
	ret.objAttrs["classid"] = classid;

	if (mimeType)
		ret.embedAttrs["type"] = mimeType;

	return ret;
}

function AC_FL_GetContent(){
	var ret = AC_GetArgs(arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
	return AC_Generate(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_FL_RunContent(){
	document.write(AC_FL_GetContent(arguments));
}

function AC_SW_GetContent(){
	var ret = AC_GetArgs(arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000", null);
	return AC_Generate(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
	document.write(AC_SW_GetContent(arguments));
}
